package com.ruoyi.smart.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.smart.domain.SmartProductTestRecord;
import com.ruoyi.smart.service.ISmartProductTestRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品测试记录Controller
 * 
 * @author minwei
 * @date 2022-10-20
 */
//@Api("产品测试记录")
@RestController
@RequestMapping("/smart/testrecord")
public class SmartProductTestRecordController extends BaseController
{
    @Autowired
    private ISmartProductTestRecordService smartProductTestRecordService;

    /**
     * 查询产品测试记录列表
     */
    //@ApiOperation("查询产品测试列表")
    @PreAuthorize("@ss.hasPermi('smart:testrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmartProductTestRecord smartProductTestRecord)
    {
        startPage();
        List<SmartProductTestRecord> list = smartProductTestRecordService.selectSmartProductTestRecordList(smartProductTestRecord);
        return getDataTable(list);
    }

    @GetMapping("/insertInfo")
    public int insertInfo(){
        return smartProductTestRecordService.insertInfo();
    }

    @PreAuthorize("@ss.hasPermi('smart:testrecord:list')")
    @GetMapping("/UnQualityList")
    public TableDataInfo UnQualityList(SelectParam selectParam)
    {
        startPage();
        selectParam.setTestState("不合格");
        List<SmartProductTestRecord> list = smartProductTestRecordService.selectSmartProductTestRecordList(selectParam.getOrganization(),selectParam.getPlan(),selectParam.getProductModel(),selectParam.getTestState());
        return getDataTable(list);
    }

    /**
     * 导出产品测试记录列表
     */
    @PreAuthorize("@ss.hasPermi('smart:testrecord:export')")
    @Log(title = "产品测试记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmartProductTestRecord smartProductTestRecord)
    {
        List<SmartProductTestRecord> list = smartProductTestRecordService.selectSmartProductTestRecordList(smartProductTestRecord);
        ExcelUtil<SmartProductTestRecord> util = new ExcelUtil<SmartProductTestRecord>(SmartProductTestRecord.class);
        util.exportExcel(response, list, "产品测试记录数据");
    }

    /**
     * 获取产品测试记录详细信息
     */
    //@ApiOperation("获取产品测试记录详细信息")
    @PreAuthorize("@ss.hasPermi('smart:testrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smartProductTestRecordService.selectSmartProductTestRecordById(id));
    }

    /**
     * 新增产品测试记录
     */
    //@ApiOperation("新增产品测试记录")
    @PreAuthorize("@ss.hasPermi('smart:testrecord:add')")
    @Log(title = "产品测试记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmartProductTestRecord smartProductTestRecord)
    {
        return toAjax(smartProductTestRecordService.insertSmartProductTestRecord(smartProductTestRecord));
    }

    /**
     * 修改产品测试记录
     */
    //@ApiOperation("修改产品测试记录")
    @PreAuthorize("@ss.hasPermi('smart:testrecord:edit')")
    @Log(title = "产品测试记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmartProductTestRecord smartProductTestRecord)
    {
        return toAjax(smartProductTestRecordService.updateSmartProductTestRecord(smartProductTestRecord));
    }

    /**
     * 删除产品测试记录
     */
    //@ApiOperation("删除产品测试记录")
    @PreAuthorize("@ss.hasPermi('smart:testrecord:remove')")
    @Log(title = "产品测试记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smartProductTestRecordService.deleteSmartProductTestRecordByIds(ids));
    }

    class SelectParam extends BaseEntity {
        String organization;
        String plan;
        String productModel;
        String testState;

        public String getOrganization() {
            return organization;
        }

        public void setOrganization(String organization) {
            this.organization = organization;
        }

        public String getPlan() {
            return plan;
        }

        public void setPlan(String plan) {
            this.plan = plan;
        }

        public String getProductModel() {
            return productModel;
        }

        public void setProductModel(String productModel) {
            this.productModel = productModel;
        }

        public String getTestState() {
            return testState;
        }

        public void setTestState(String testState) {
            this.testState = testState;
        }
    }
}
